<?php
/*********************************************************************************
 * Copyright (C) 2011-2013 X2Engine Inc. All Rights Reserved.
 *
 * X2Engine Inc.
 * P.O. Box 66752
 * Scotts Valley, California 95067 USA
 *
 * Company website: http://www.x2engine.com
 * Community and support website: http://www.x2community.com
 *
 * X2Engine Inc. grants you a perpetual, non-exclusive, non-transferable license
 * to install and use this Software for your internal business purposes.
 * You shall not modify, distribute, license or sublicense the Software.
 * Title, ownership, and all intellectual property rights in the Software belong
 * exclusively to X2Engine.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT.
 ********************************************************************************/

Yii::app()->clientScript->registerCss("viewProfile", "

.avatar-upload {
    border: 3px solid #f8f8f8;
    -webkit-border-radius:8px;
	-moz-border-radius:8px;
	-o-border-radius:8px;
	border-radius:8px;
}

");

Yii::app()->clientScript->registerScript('avatarUploader',"
function showAttach() {
	e=document.getElementById('attachments');
	if(e.style.display=='none')
		e.style.display='block';
	else
		e.style.display='none';
}
var legal_extensions = ['png','gif','jpg','jpe','jpeg'];        // array with allowed extensions

function checkPictureExt(el, sbm) {
// - www.coursesweb.net
	// get the file name and split it to separe the extension
	var name = el.value;
	var ar_name = name.split('.');
	ar_ext = ar_name[ar_name.length - 1].toLowerCase();
	// alert(ar_ext);
	// check the file extension
	var re = 0;
	for(i in legal_extensions) {
		if(legal_extensions[i] == ar_ext) {
			re = 1;
			break;
		}
	}
	// if re is 1, the extension is in the allowed list
	if(re==1) {
		// enable submit
		$(sbm).removeAttr('disabled');
		$('#photo-form').submit();
	}
	else {
		// delete the file name, disable Submit, Alert message
		el.value = '';
		$(sbm).attr('disabled','disabled');
		alert('\".'+ ar_ext+ '\" is not an file type allowed for upload');
	}


}

$(function() {
	$('.file-wrapper').qtip({
		content: 'Choose Profile picture.'
	});
});

",CClientScript::POS_HEAD);

$attributeLabels = $model->attributeLabels();
?>








<div class="user-profile row-fluid" id="user-profile-1">
        <div class="span3 center" style="margin-top:20px;">
                <div>
                        <span class="profile-picture" style="border: none !important;box-shadow:none !important;">
                                    <span class="file-wrap3per">
                                   <?php
                                   // getimagesize()

                                   if(isset($model->avatar) && $model->avatar!='' && file_exists($model->avatar)) {

                                           $imgSize = @getimagesize($model->avatar);
                                           // die( var_dump($imgSize));
                                           if(!$imgSize)
                                                   $imgSize = array(45,45);

                                           $maxDimension = max($imgSize[0],$imgSize[1]);

                                           $scaleFactor = 1;
                                           if($maxDimension > 250)
                                                   $scaleFactor = 250 / $maxDimension;

                                           $imgSize[0] = round($imgSize[0] * $scaleFactor);
                                           $imgSize[1] = round($imgSize[1] * $scaleFactor);
                                           // echo var_dump($imgSize);

                                           echo '<img class="editable editable-click editable-empty" width="'.$imgSize[0].'" height="'.$imgSize[1].'" class="avatar-upload" '.
                               'src="'.Yii::app()->request->baseUrl.'/'.$model->avatar.'" />';
                                   } else
                                           echo '<img class="editable editable-click editable-empty"  width="45" height="45" src='.Yii::app()->request->baseUrl."/uploads/default.png".'>';
                                   ?>
                                   <?php if($model->username == Yii::app()->user->getName()) {
                                           echo CHtml::form('uploadPhoto/'.$model->id,'post',array('enctype'=>'multipart/form-data', 'id'=>'photo-form'));
                                           echo CHtml::fileField('photo','',array('id'=>'photo','onchange'=>"checkPictureExt(this, '#avatarSubmit')")).'<br />';
                                           // echo CHtml::submitButton(Yii::t('app','Submit'),array('id'=>'avatarSubmit','disabled'=>'disabled'),array('class'=>'x2-button btn btn-mini  btn-yellow'));
                                           echo CHtml::endForm();
                                   } ?>
                                   <?php /*<button type="submit" class="x2-button btn btn-mini  btn-yellow" name="photo-submit"><?php echo Yii::t('profile', 'Choose Picture'); ?></button> */ ?>
                                   </span>                           
                        </span>

                        <div class="space-4"></div>

                        <div class="width-80 label label-info label-large arrowed-in arrowed-in-right">
                                <div class="inline position-relative">
                                        <a data-toggle="dropdown" class="user-title-label dropdown-toggle" href="#">
                                                <i class="icon-circle light-green middle"></i>
                                                &nbsp;
                                                <span class="white middle bigger-120"><?php echo CHtml::encode($model->fullName); ?></span>
                                        </a>

                                </div>
                        </div>
                </div>

                <div class="space-6"></div>
        </div>

        <div class="span9">
                <div class="space-12"></div>
                <div class="profile-user-info profile-user-info-striped">
                        <div class="profile-info-row">
                                <div class="profile-info-name"><?php echo $attributeLabels['fullName']; ?></div>
                                <div class="profile-info-value">
                                        <span id="username" class="editable editable-click"><?php echo CHtml::encode($model->fullName); ?></span>
                                </div>
                        </div>
                    
                        <div class="profile-info-row">
                                <div class="profile-info-name"><?php echo $attributeLabels['tagLine']; ?></div>
                                <div class="profile-info-value">
                                        <span id="username" class="editable editable-click"><?php echo CHtml::encode($model->tagLine); ?></span>
                                </div>
                        </div>
                    
                        <div class="profile-info-row">
                                <div class="profile-info-name"><?php echo $attributeLabels['username']; ?></div>
                                <div class="profile-info-value">
                                        <span id="username" class="editable editable-click"><?php echo CHtml::encode($model->username); ?></span>
                                </div>
                        </div>
                    
                        <div class="profile-info-row">
                                <div class="profile-info-name"><?php echo $attributeLabels['officePhone']; ?></div>
                                <div class="profile-info-value">
                                        <span id="username" class="editable editable-click"><?php echo CHtml::encode($model->officePhone); ?></span>
                                </div>
                        </div>
                    
                        <div class="profile-info-row">
                                <div class="profile-info-name"><?php echo $attributeLabels['cellPhone']; ?></div>
                                <div class="profile-info-value">
                                        <span id="username" class="editable editable-click"><?php echo CHtml::encode($model->cellPhone); ?></span>
                                </div>
                        </div>
                    
                        <div class="profile-info-row">
                                <div class="profile-info-name"><?php echo $attributeLabels['emailAddress']; ?></div>
                                <div class="profile-info-value">
                                        <span id="username" class="editable editable-click"><?php echo CHtml::encode($model->emailAddress); ?></span>
                                </div>
                        </div>
                    
                        <div class="profile-info-row">
                                <div class="profile-info-name"><?php echo $attributeLabels['googleId']; ?></div>
                                <div class="profile-info-value">
                                        <span id="username" class="editable editable-click"><?php echo CHtml::encode($model->googleId); ?></span>
                                </div>
                        </div>
                    
                        <div class="profile-info-row">
                                <div class="profile-info-name"><?php echo $attributeLabels['emailSignature']; ?></div>
                                <div class="profile-info-value">
                                        <span id="username" class="editable editable-click"><?php echo $model->getSignature(true); ?></span>
                                </div>
                        </div>

    
                </div>

                <div class="space-20"></div>

        </div>
</div>

